﻿namespace ScrumLite.WebUx.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using ScrumLite.Services;
    using ScrumLite.Services.Contracts;

    public class MockRolesService : IRolesService
    {
        public bool GetProjectRoleCalled { get; set; }
        public bool GetProjectRolesCalled { get; set; }
        public bool GetAbilitiesCalled { get; set; }
        public bool AddRoleToProjectCalled { get; set; }
        public string AddedRole { get; set; }
     
        private static List<ProjectRole> roles;
        private static List<Ability> abilities;

        public MockRolesService()
        {
            roles = new List<ProjectRole>();
            roles.Add(new ProjectRole { Id = Guid.NewGuid(), Name = "Developer Sr." });
            roles.Add(new ProjectRole { Id = Guid.NewGuid(), Name = "Developer Jr." });
            roles.Add(new ProjectRole { Id = Guid.NewGuid(), Name = "Architect" });
            roles.Add(new ProjectRole { Id = Guid.NewGuid(), Name = "Technical Writer" });

            abilities = new List<Ability>();
            abilities.Add(new Ability { Id = Guid.NewGuid(), Name = "C#" });
            abilities.Add(new Ability { Id = Guid.NewGuid(), Name = "ASP.Net" });
            abilities.Add(new Ability { Id = Guid.NewGuid(), Name = "Security Token Service (STS)" });
            abilities.Add(new Ability { Id = Guid.NewGuid(), Name = "Windows Comunication Foundation (WCF)" });
            abilities.Add(new Ability { Id = Guid.NewGuid(), Name = "Cardspace" });
        }

        public ProjectRole GetProjectRole(string roleId)
        {
            this.GetProjectRoleCalled = true;

            return roles[0];
        }

        public Collection<ProjectRole> GetProjectRoles(string projectId)
        {
            this.GetProjectRolesCalled = true;

            var projectRoles = (from r in roles                                  
                                  select r).ToList();

            return new Collection<ProjectRole>(projectRoles);
        }

        public Collection<Ability> GetAbilities(string projectId, string roleId)
        {
            this.GetAbilitiesCalled = true;

            var roleAbilities = (from a in abilities
                                   select a).ToList();

            return new Collection<Ability>(roleAbilities);
        }

        public void AddRoleToProject(string projectId, string roleName, string[] abilityIds)
        {
            this.AddRoleToProjectCalled = true;
            this.AddedRole = roleName;
        }
    }
}
